package com.hengxinguotong.zhihuichengjian.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.Train;
import com.hengxinguotong.zhihuichengjian.widget.MarqueeTextView;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @CopyRight 恒信国通信息科技
 * @Author WuLei
 * @Date 2018/11/1
 */

public class StudyRecordAdapter extends RecyclerAdapter<Train, StudyRecordAdapter.StudyRecordViewHolder> {

    public StudyRecordAdapter(Context context, List<Train> dataList) {
        super(context, dataList);
    }

    @Override
    public StudyRecordViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.item_study_record, null);
        return new StudyRecordViewHolder(view);
    }

    @Override
    public void onBindViewHolder(StudyRecordViewHolder holder, int position) {
        holder.bindData(dataList.get(position));
    }

    public class StudyRecordViewHolder extends RecyclerAdapter.BaseViewHolder<Train>{
        @BindView(R.id.name_tv)
        MarqueeTextView nameTv;
        @BindView(R.id.hour_tv)
        HXTextView hourTv;
        @BindView(R.id.person_tv)
        HXTextView personTv;
        @BindView(R.id.study_type_tv)
        HXTextView studyTypeTv;
        @BindView(R.id.study_unit_tv)
        HXTextView studyUnitTv;
        @BindView(R.id.date_tv)
        HXTextView dateTv;
        @BindView(R.id.time_tv)
        HXTextView timeTv;

        public StudyRecordViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }

        public void bindData(final Train train){
            nameTv.setText(train.getTrainName());
            hourTv.setText(train.getTrainPeriod() + "学时");
            studyUnitTv.setText(train.getTrainDepart());
            studyTypeTv.setText(train.getTrainType());
            dateTv.setText(train.getTrainTime());

            personTv.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    itemClickListener.onItemClick(train);
                }
            });
        }
    }
}
